<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title><?=$this->page_title;?></title>
<link rel="stylesheet" type="text/css" href="/style/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/swiper.min.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/xshop.css?ver=20180810" />
<script src="/style/js/jquery-1.12.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/xShop.js" type="text/javascript" charset="utf-8"></script>
<style>
.btnwrap .btn-mexl{
background: #999;
color: #ccc;
}


.btnwrap .btn-mexl.active{
background: #FF0101;
color: #fff;
}


.iptform .item-ipt span.name{

font-size: .32rem;
}

.iptform .item-ipt .btn-huoqu {
border-radius: 1rem;
right: .5rem;

}

.iptform .item-ipt .txtpla {
margin-left: -0.5rem;
font-size: .32rem;

}
</style>
</head>
<body>
<div class="outwrap">
	<!--top-->	
	<!-- <div class="topbar clearfix topvh">
		<a href="/mystore/account_manage" class="btn-back">
			<i class="ico-back"></i><span>更改手机号</span>
		</a>
	</div> -->
   <div class="meinner-adr-add"  >
    <div class="iptform iptformm30" style="background: #f1f1f1;>
    <form action="" method="post">
      <?php
      if($_GET['a']=="m")
      {
      ?>
      <div style="width: 100%; height: 1.28rem; text-align: center; margin-bottom: .4rem;">
        <img src="/style/wei/images/logo_color.png" style="width: auto; height: 1rem; margin: .38rem 0;">
      </div>
      <div style="width: 100%; height: auto; line-height: 1rem; font-size: .30rem; text-align: center; color: #333; border-bottom: 1px solid #f2f2f2;margin-bottom:-0.3rem;font-weight:bold;">
          为了您的帐号安全请绑定手机号码
      </div>
      <?
      }
      ?>      
      <div class="item-ipt" style="margin:.2rem 0; background:#fff;">
        <span class="name" style="margin:0 0.5rem ;">手机号码 </span><input type="tel" maxlength="11" placeholder="请填写11位手机号码" class="txtpla" name="mobile" id="mobile"/>
      </div>
     
      <div class="item-ipt" style="margin:.2rem 0; background:#fff;">
        <span class="name" style="margin:0 0.5rem ;">验证码 </span><input type="tel" maxlength="6" id="check_code" placeholder="请填写短信验证码" class="txtpla" /><a href="javascript:_getsmscode();" class="btn-huoqu">获取</a>
      </div>      
     <?php
      if($_GET['a']=="m" && $this->user['member_level'] == 0)
      {
      ?>
      <div class="item-ipt"style="margin:.2em 0; background:#fff;">
        <span class="name" style="margin:0 0.5rem ;">姓名 </span><input type="text" maxlength="30" placeholder="请填写姓名" class="txtpla" name="realname" id="realname"/>
      </div>
      <div class="item-ipt" style="margin:.2rem 0; background:#fff;">
        <span class="name" style="margin:0 0.5rem ;">邀请码 </span><input type="tel" value="<?=$this->recode;?>" id="recode" placeholder="请填写邀请码" class="txtpla" />        
      </div>
      <!-- <div style=" margin-left: 2.2rem; line-height: .8rem; font-size: .28rem; color: #FF0101;margin-top:-0.3rem">填写有效的邀请码可获赠4张免邮券</div> -->
      <div class="agreen" style="width: 100%; height: auto; line-height: 1rem; font-size: .30rem; text-align: center; color: #333; border-bottom: 1px solid #f2f2f2;margin-bottom:-0.3rem;font-weight:bold;">同意 <a href="/user/xieyi">西海良品服务协议</a></div>
      <?php
      }
      ?>
     
     
    </form>
    </div>
    <div class="btnwrap">
     <?php
      if($_GET['a']=="m")
      {
      ?>
      <input type="button" class="btn-mexl btn-bc" id="sub_btn" value="注册" />
      <?php }else{?>
       <input type="button" class="btn-mexl btn-bc active" id="sub_btn" value="保存" />
      <?php }?>
    </div>
  </div>
</div>
<script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
<script>

$(function(){
    $('.agreen').on('click',function(){
        if($(this).hasClass('active')){
            $(this).removeClass('active');
            $("#sub_btn").removeClass("active");
        }else{
            $(this).addClass('active');
            $("#sub_btn").addClass("active");
        }
    });
});

var _ref = '<?=$_GET['ref '] != "" ? Rfc::decode($_GET['ref ']) : '';?>',
_a = '<?=$_GET['a'];?>',
_c = '<?=$_GET['c'];?>';
$(document).ready(function() {
    $("#sub_btn").click(function() {

      if( $(this).hasClass("active") )
      {
          if ($("#mobile").val() == "") {
            swal("手机号码不能为空");
            return false;
          }
          
          if ($("#check_code").val() == "") {
              swal("请填写短信验证码");
              return false;
          }

          if ($("#realname").val() == "" && _a!="") {
              swal("请填写姓名");
              return false;
          }
          if(!$('.agreen').hasClass("active")  && _a!="")
          {
              swal("认真阅读并同意协议才能注册");
              return false;
          }      
         
          $.post("/user/ajax", {
              "act": "save_mobile",
              "mobile": $("#mobile").prop("value"),
              "smscode": $("#check_code").prop("value"),
              "recode":$("#recode").prop("value"),
              "realname":$("#realname").prop("value"),
              "mr": Math.random()
          }, function(data) {
              if (data.code == 200) {
                  swal("修改成功！", false, "success");
                  setTimeout(function() {
                      if (_a != "") {
                          if(_c=="cart")
                          {
                            window.location.href = "/cart/cart";
                          }
                          else
                          {
                            window.location.href = "/user/index";
                          }
                          
                      } else {
                          window.history.back(1);
                      }
                  }, 2100);
              } else if (data.code == 901) {
                  swal("验证码错误", false, "error");
              } else if (data.code == 902) {
                  swal("手机号码格式不正确", false, "error");
              } else if (data.code == 903) {
                  swal("手机号码已存在", false, "error");
              } else if (data.code == 904) {
                  swal("优惠券发放失败", false, "error");
              } else if (data.code == 905) {
                  swal("邀请码无效", false, "error");
              }
              
          }, 'json');
      }

        
    });
});
var _smscodeStat = false,
    _smscodeSec = 60,
    parm = /^(13|14|15|16|17|18|19)+([0-9]{9})$/;

function _smscodeTimer() {
    if (_smscodeStat && _smscodeSec > 0) {
        $(".btn-huoqu").html(_smscodeSec + '秒后重发');
        _smscodeSec -= 1;
        setTimeout("_smscodeTimer();", 1000);
    } else {
        _smscodeStat = false;
        _smscodeSec = 60;
        $(".btn-huoqu").html('获取');
    }
}

function _getsmscode() {
    if (!_smscodeStat) {
        var _do = true;
        if ($("#mobile").prop("value") == "") {
            swal("请填写手机号码");
            _do = false;
        } else if (!parm.test($("#mobile").prop("value"))) {
            swal("手机号码格式不正确");
            _do = false;
        }
        if (_do) {
            $.post("/user/ajax", {
                "act": "sendsmscode",
                "mobile": $("#mobile").prop("value"),
                "mr": Math.random()
            }, function(msg) {
                console.log(msg);
                if (msg.code == 200) {
                    _smscodeStat = true;
                    _smscodeTimer();
                    swal("验证码已发送!");
                } else if (msg.code == 404) {
                    swal("手机号码已被注册");
                } else if (msg.code == 403) {
                    swal("保存验证码失败");
                } else if (msg.code == 409) {
                    swal("验证码发送失败");
                } else if (msg.code == 900) {
                    swal("手机号码错误");
                } else {
                    swal("发送验证码失败");
                }
            },"json");
        }
    }
}
</script>
</body>
</html>
